#include "stdafx.h"
#include "Lock.h"
#include "SingleObjWrapper.h"

// all the CSingleObjWrapper is allocted in the heap, and only the wrapper manager can delete it
CSingleObjWrapper::~CSingleObjWrapper()
{
	if(m_pRawPointer != NULL && m_destoryFun != NULL)
	{
		m_destoryFun( m_pRawPointer );
	}
}

CSingleObjWrapper::CSingleObjWrapper(void * p, DESTORY_PROC destory, size_t memSize)
	: CObjectWrapper()
{
	// store the raw pointer
	m_pRawPointer = p;
	
	// count the size of the pointer
	if(p == NULL)
	{
		m_size=0;
	}
	else
	{
		m_size = memSize;
	}

	// set the ref count 
	m_count = 1;

	// store the finalize
	m_destoryFun = destory;
}

int CSingleObjWrapper::AddRef()
{
	return m_count++;
}

int CSingleObjWrapper::Release()
{
	return m_count--;
}
